<?php
include("common.php");

$fid  = isset($_GET["fid"]) && !empty($_GET["fid"]) ? trim(strip_tags($_GET["fid"])) : "";

if(!$fid) {
	header("location:/");
	exit;
}

$result = $sch->getFileInfo($fid);

$arr_file_info   = $result->data;
$bol_file_status = $result->status;

if($bol_file_status != OK) {
	$str_file_status = $result->error;	
} else {
	$str_file_status = "文件有效";
}

if($bol_file_status === FILE_NOT_EXISTS) {
	header("HTTP/1.1 404 Not Found");
	require("404.htm");
	exit;
}

$tpl->assign("file_info", $arr_file_info);

$disk_filter    = $sch->getDiskFilter();
$sort_filter    = $sch->getSortFilter();
$size_filter    = $sch->getSizeFilter();
$last_searches  = $sch->getLastSearches(10);
$last_downloads = $sch->getLastDownloads(10);

$intro = "{$lang["file_info_type"]}:{$arr_file_info->type},{$lang["file_info_size"]}:{$arr_file_info->size},{$lang["file_info_source"]}:{$arr_file_info->site},";
$intro.= "{$lang["file_info_created"]}:{$arr_file_info->created},{$lang["file_info_checked"]}:{$arr_file_info->checked}。";
foreach($arr_file_info->data as $record) {
	$intro.= $record->name;
	if($record->intro && trim($record->intro) != trim($record->name)) {
		$intro.= "-".$record->intro;
	}
	$intro.= ",";
}
$intro = substr($intro, 0, -1);

if(strlen($intro) > 150) {
	$intro = mb_substr($intro, 0, 150, "UTF-8");
}

$tpl->assign(array(
"disk_filter"=>$disk_filter,
"sort_filter"=>$sort_filter,
"size_filter"=>$size_filter,
"last_searches"=>$last_searches,
"last_downloads"=>$last_downloads,
"search_results"=>$search_results,
"word"=>$word,
"seo_title"=>str_replace(array("{keyword}", "{site}"), array($arr_file_info->name."({$arr_file_info->size})", $arr_file_info->site), $config["seo_detail_title"]),
"seo_keywords"=>str_replace(array("{keyword}", "{site}"), array($arr_file_info->name, $arr_file_info->site), $config["seo_detail_keywords"]),
"seo_description"=>str_replace("{intro}", $intro, $config["seo_detail_description"]),
"bol_file_status"=>$bol_file_status,
"str_file_status"=>$str_file_status
));

$tpl->assign("search_box", $tpl->fetch("search_box.html"));
$tpl->assign("left", $tpl->fetch("left.html"));

$tpl->display("header.html", "detail.html", "footer.html");
?>